package vcp.client.reports;

import java.io.Serializable;
import java.util.ArrayList;

import vcp.enums.ReportType;
/**
 * 
 * @author VCP team
 *<p> abstract class for Reports </p>
 */
public abstract class ReportAbstract implements Serializable
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1935971087065804190L;

	// ****************************************************************************************************************************
	// Setter-Getter methods
	// ****************************************************************************************************************************
	private final ReportType type;
	/**
	 * getter
	 * @return report type
	 */
	public ReportType getType ()
	{
		return this.type;
	}

	/**
	 * holds reference to DB periodic rows
	 */
	protected final ArrayList <IWrapperConverter> reportDataRow;

	/** Protected constructor, may only be accessed from derived classes **/
	protected ReportAbstract ( ReportType type )
	{
		this.type = type;
		this.reportDataRow = new ArrayList <>();
	}

	// ****************************************************************************************************************************
	// Public methods
	// ****************************************************************************************************************************
	/**
	 * checks if report is not empty
	 * @return true if not empty
	 */
	public boolean hasData ()
	{
		return ! this.reportDataRow.isEmpty();
	}
	/**
	 * check if report is empty
	 * @return true if empty
	 */
	public boolean isEmptyReport ()
	{
		return false;
	}

	public abstract String[] getHeaders ();
	/**
	 * get rows
	 * @return object[][]
	 */
	public final Object[][] getRows ()
	{
		Object[][] convertedColumn = new Object[this.reportDataRow.size()][];
		for ( int i = 0; i < this.reportDataRow.size(); i ++ )
		{
			convertedColumn[i] = this.reportDataRow.get(i).toObjectArray();
		}

		return convertedColumn;
	}

	// ****************************************************************************************************************************
	// Wrapper interface for reports
	// ****************************************************************************************************************************
	protected interface IWrapperConverter
	{
		/**
		 * @return Wrapped row as Object[]
		 */
		Object[] toObjectArray ();
	}
}
